<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Shopping-Car</title>

</head>

<body>
    <script>
        let commodity1 = {
            price: 0,
            num: 0,
            buy(price, num) {
                console.log('商品价格：' + price + '   数量：' + num);
                totol = price * num;
                Car.push(totol);
            }
        }

        let commodity2 = {
            price: 0,
            num: 0,
            buy(price, num) {
                console.log('商品价格：' + price + '   数量：' + num);
                totol = price * num;
                Car.push(totol);
            }
        }

        let commodity3 = {
            price: 0,
            num: 0,
            buy(price, num) {
                console.log('商品价格：' + price + '   数量：' + num);
                totol = price * num;
                Car.push(totol);
            }
        }
        const Car = [];

        function settle() {
            let totolPrice = 0;
            for (let i = 0; i < Car.length; i++) {
                totolPrice += Car[i]
            }
            console.log('总价格：' + totolPrice);
        }
        commodity1.buy(233, 2);
        commodity2.buy(55, 2);
        commodity3.buy(12, 2);
        settle();
    </script>
</body>

</html>